<?php

class OrderTest extends BaseTest
{
    public function testInsert()
    {
        $class = new \Orm\Order\OrderClass();
		$class['order_code'] = $this->testStr();
		$class['article_id'] = $this->testNum();
		$class['seller_uid'] = $this->testNum();
		$class['buyer_uid'] = $this->testNum();
		$class['adds'] = $this->testStr();
		$class['contact'] = $this->testStr();
		$class['tel'] = $this->testStr();
		$class['total_price'] = $this->testNum();
		$class['remark'] = $this->testStr();
		$class['pay_status'] = $this->testNum();
		$class['pay_datetime'] = $this->testStr();
		$class['appointment_time'] = $this->testStr();
		$class['logistics_name'] = $this->testStr();
		$class['logistics_numbers'] = $this->testStr();


        $class->insert();
        $result_class = new \Orm\Order\OrderClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['order_code'],$result_class['order_code']);
		$this->assertEquals($class['article_id'],$result_class['article_id']);
		$this->assertEquals($class['seller_uid'],$result_class['seller_uid']);
		$this->assertEquals($class['buyer_uid'],$result_class['buyer_uid']);
		$this->assertEquals($class['adds'],$result_class['adds']);
		$this->assertEquals($class['contact'],$result_class['contact']);
		$this->assertEquals($class['tel'],$result_class['tel']);
		$this->assertEquals($class['total_price'],$result_class['total_price']);
		$this->assertEquals($class['remark'],$result_class['remark']);
		$this->assertEquals($class['pay_status'],$result_class['pay_status']);
		$this->assertEquals($class['pay_datetime'],$result_class['pay_datetime']);
		$this->assertEquals($class['appointment_time'],$result_class['appointment_time']);
		$this->assertEquals($class['logistics_name'],$result_class['logistics_name']);
		$this->assertEquals($class['logistics_numbers'],$result_class['logistics_numbers']);

        return $result_class;
    }

    /**
     * @depends testInsert
     */
    public function testUpdate($class)
    {
		$class['order_code'] = $this->testStr();
		$class['article_id'] = $this->testNum();
		$class['seller_uid'] = $this->testNum();
		$class['buyer_uid'] = $this->testNum();
		$class['adds'] = $this->testStr();
		$class['contact'] = $this->testStr();
		$class['tel'] = $this->testStr();
		$class['total_price'] = $this->testNum();
		$class['remark'] = $this->testStr();
		$class['pay_status'] = $this->testNum();
		$class['pay_datetime'] = $this->testStr();
		$class['appointment_time'] = $this->testStr();
		$class['logistics_name'] = $this->testStr();
		$class['logistics_numbers'] = $this->testStr();


        $class->update();
        $result_class = new \Orm\Order\OrderClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['order_code'],$result_class['order_code']);
		$this->assertEquals($class['article_id'],$result_class['article_id']);
		$this->assertEquals($class['seller_uid'],$result_class['seller_uid']);
		$this->assertEquals($class['buyer_uid'],$result_class['buyer_uid']);
		$this->assertEquals($class['adds'],$result_class['adds']);
		$this->assertEquals($class['contact'],$result_class['contact']);
		$this->assertEquals($class['tel'],$result_class['tel']);
		$this->assertEquals($class['total_price'],$result_class['total_price']);
		$this->assertEquals($class['remark'],$result_class['remark']);
		$this->assertEquals($class['pay_status'],$result_class['pay_status']);
		$this->assertEquals($class['pay_datetime'],$result_class['pay_datetime']);
		$this->assertEquals($class['appointment_time'],$result_class['appointment_time']);
		$this->assertEquals($class['logistics_name'],$result_class['logistics_name']);
		$this->assertEquals($class['logistics_numbers'],$result_class['logistics_numbers']);

        return $result_class;
    }

    /**
     * @depends testUpdate
     */

    public function testDelete($class)
    {
        $class->delete($class['id']);

        $result_class = new \Orm\Order\OrderClass();
        $result_class->loadById($class['id']);
        $this->assertEquals(1, $result_class['is_del']);
        return $result_class;
    }


    /**
     * @depends testInsert
     */
    public static function testClean($class)
    {
        if ($class['id']) {
            $class->realDelete($class['id']);
        }
    }
}